import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/index.vue')
  },
  {
    path: '/home',
    name: 'home',
    redirect: "/home/wiki",
    component: () => import('@/views/home/home.vue'),
    children: [
      {
        path: '/home/wiki',
        name: 'wiki',
        component: () => import('@/views/home/homeChild/wiki.vue')
      },
      {
        path: '/home/classifyQuery',
        name: 'classifyQuery',
        component: () => import('@/views/home/homeChild/classifyQuery.vue')
      },
      {
        path: '/home/naturalResEstimate',
        name: 'naturalResEstimate',
        meta:{
          keepAlive:true,
        },
        component: () => import('@/views/home/homeChild/naturalResEstimate.vue')
      },
      {
        path: '/home/naturalResQuery',
        name: 'naturalResQuery',
        component: () => import('@/views/home/homeChild/naturalResQuery.vue')
      },
      {
        path: '/home/siteSelect',
        name: 'siteSelect',
        
        component: () => import('@/views/home/homeChild/siteSelect.vue')
      },
      {
        path: '/home/strategyEstimate',
        name: 'strategyEstimate',
        meta:{
          keepAlive:true,
        },
        component: () => import('@/views/home/homeChild/strategyEstimate.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/lightCalc',
    name: 'lightCalc',
    component: () => import('@/views/home/homeChild/lightCalc.vue')
  },
  {
    path: '/windCalc',
    name: 'windCalc',
    component: () => import('@/views/home/homeChild/windCalc.vue')
  },
  {
    path: '/outPut',
    name: 'outPut',
    component: () => import('@/views/home/homeChild/outPut.vue')
  },
  {
    path: '*',
    name: '404',
    component: () => import('@/views/404.vue')
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  // 进行身份验证检查
  if (to.path == '/login') {
    next()
  } else {

    if (localStorage.getItem("token")) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
